import Vue from "vue";
import Vuex from "vuex";

Vue.use(Vuex);
import vuexPersist from "vuex-persist";
export default new Vuex.Store({
  state: {
    /**
    * token
    */
    users: [],
    /**
     * 存购物车数据
     */
    pic: [],
    /**
     * 存储搜索数据
     */
    searchdata: [],
  },
  mutations: {
    /**
     * 保存搜索
     */
    addSearch(state, playout) {
      state.searchdata = playout
      console.log(state.searchdata, "搜搜");
    },
    /**
     * 保存用户名
     */
    setuser(state, playout) {
      state.users = playout
      console.log(state.users);
    },
    picss(state, playout) {
      state.pic = playout
      console.log(state.pic);
    }

  },
  actions: {
    /**
     * 退出登录
     */
    cleantoken({ commit }) {
      commit("setuser", "")
      localStorage.removeItem("vuex");
    }
  },


  plugins: [
    new vuexPersist({
      localstorage: window.localStorage,
    }).plugin,
  ],
});
